package com.example.cloud.web.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

/**
 * @author wjwjtftf Created on 2017/9/26.
 */
@Service
public class NameService {

	private final String SERVICE_NAME = "cloud-service";

	@Resource
	private RestTemplate restTemplate;

	@HystrixCommand(fallbackMethod = "fallbackGetServiceName")
	public String getServiceName() {
		return restTemplate.getForObject("http://" + SERVICE_NAME + "/app-name", String.class);
	}

	private String fallbackGetServiceName() {
		return "服务不可用";
	}
}
